<%@page import="com.wanmait.hotelManage.vo.OfficialNews"%>
<%@page import="com.wanmait.hotelManage.vo.Pager"%>
<%@page import="com.wanmait.hotelManage.vo.RoomType"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path=request.getContextPath();
%>
<jsp:include page="/manage/inc/header.jsp"/>
<jsp:include page="/manage/inc/menu.jsp"/>
<%
	List<OfficialNews> officialNewss=(List<OfficialNews>)request.getAttribute("officialNewss");
	Pager pager=(Pager)request.getAttribute("pager");
%>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<%=path%>/manage/index.jsp">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">通知管理</span></div>
        </div>
        <!-- 搜索 -->
        <div class="search-wrap">
            <div class="search-content">
                <form id="sea" action="<%=path %>/manage/OfficialNewsServlet?action=search" method="post">
                    <table class="search-tab">
                        <tr>
                           <!-- <th width="120">选择分类:</th>
                             <td>
                                <select name="search-sort" id="">
                                    <option value="">全部</option>
                                    <option value="19">精品界面</option><option value="20">推荐界面</option>
                                </select>
                            </td> -->
                            <th width="70">搜索</th>
                            <td>关键词:<input placeholder="关键词" name="keyword" value="" id="keyword" type="text"></td>
                            
                            <td><input class="btn btn-primary btn2" id="search" name="sub" value="查询" type="button">
                            	<span id="keywordMsg"></span>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <!-- 搜索结束 -->
        
        <div class="result-wrap">
            
                <div class="result-title">
                    <div class="result-list">
                        <a href="<%=path%>/manage/officialNews/insert.jsp"><i class="icon-font"></i>发送消息</a>
                        <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                    </div>
                </div>
                
                <div class="result-content">
                    <table id="tt" class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                             <th>序号</th> 
                            <!-- <th>ID</th> -->
                            <th>标题</th>                         
                            <th>内容</th>
                            <th>发送时间</th>
                            <th>操作</th>
                        </tr>
                       <%  
                       	if(officialNewss!=null){
                        for(int i=0;i<officialNewss.size();i++){
                        	OfficialNews officialNews=officialNewss.get(i);
                        	/* out.print(roomType); */
                        	%>
                        	
                        	<tr id="tr<%=officialNews.getId()%>">
                        	
                               <td class="tc"><input data-id="<%=officialNews.getId() %>" class="choose" name="id[]" value="59" type="checkbox"></td>
                               <td width="80px"><%=i+1 %></td>  
                               <td width="150px"><%=officialNews.getTitle() %></td>  
                               <td ><%=officialNews.getContent() %></td>
                               <td width="200px"><%=officialNews.getInputTime() %></td>
   
                               <td width="80px" class="tt">  
                                   <a class="link-del"  id="del<%=officialNews.getId()%>" href="#">删除</a>
                               </td>
                           </tr>
                        <% 	
                        }
                       }
                       %>
                    </table>
                    
                     <!-- 显示数字 -->
						<div style="text-align: center;">
						<%
                    if(pager!=null){
                    	 int start= 1;
                         int end =pager.getPageCount();
                         if(pager.getPageCount()>5){
                        	 start=pager.getPageNo()-2<1?1:pager.getPageNo()-2;
                        	 end=start+4;
                        	 if(end>pager.getPageCount()){
                        		 end=pager.getPageCount();
                        		 start=end-4;
                        	 }
                         }
                         %>
                         [<a class="ok" href="javascript:void(0)">上一页</a>]
                         <%
                    	for(int i=start;i<=end;i++){
                    		%>
                    		[<a class="number" href="javascript:void(0)"><%=i %></a>]
                    		<%
                    	}
                         %>
                         [<a class="no" href="javascript:void(0)">下一页</a>]
                         <%
                    }
                    %>
						</div>
 	    
                </div>
        </div>
         <!-- 显示数字 -->
						</div>
	
<jsp:include page="/manage/inc/footer.jsp"/>
<script>
	$(function() {	
		
		
		$(".no").click(function(){
			/* $(".number").css("color","black");
			$(this).css("color","red"); */
			var n=<%=pager.getPageNo()%>;
			if(n<<%=pager.getPageCount()%>){
				n++;
			}
			$.ajax({
				url:"<%=path%>/manage/OfficialNewsServlet?action=getOfficialNewss",
					data:{"pageNo":n},
						success:function(msg){
							$(".result-content").html(msg);
						}
			})
		})
		$(".ok").click(function(){
		/* $(".number").css("color","black");
		$(this).css("color","red"); */
		var n=<%=pager.getPageNo()%>;
		if(n>1){
		n--;
		}
		$.ajax({
		url:"<%=path%>/manage/OfficialNewsServlet?action=getOfficialNewss",
		data:{"pageNo":n},
			success:function(msg){
				$(".result-content").html(msg);
			}
		})
		})		
		
	
		//搜索
		$("#search").click(function() {
			var keyword=$("#keyword").val();
			if(keyword==""){
				$("#keywordMsg").html("请输入关键词");
				return;
			}
			$("#keywordMsg").empty();
			$("#sea").submit();
		})
		//换页
		$(".result-content").on("click",".number",function(){
			$(".number").css("color","black");
			$(this).css("color","red");
			var n = $(this).html();
			
			$.ajax({
				url:"<%=path%>/manage/OfficialNewsServlet?action=getOfficialNewss",
				data:{"pageNo":n},
				success:function(msg){
					$(".result-content").html(msg);
				}
			})
			
		})
		<%-- var path="<%=path%>"; --%>
		//删除
		/* $("#tt").on("click",".link-del",function() { */
			$(".link-del").click(function(){
				if(!window.confirm("你确定要删除吗")){
					return false;
				}
				var id=$(this).attr("id").substring(3);
			<%=pager.getPageNo()%>
				
				$.ajax({
					url:"<%=path%>/manage/OfficialNewsServlet?action=delete",
					data:{id:id,pageNo:<%=pager.getPageNo()%>},
					success:function(msg){
						/* $("#tr"+id).remove(); */
						$(".result-content").html(msg);
					}
				});
			});
			/* $(".link-del").bind("click",del);
			$(".link-del").live("click",del); */
		
		//全选
		$(".allChoose").click(function() {
			$(".choose").prop("checked",$(this).prop("checked"));
		})
		//批量删除
		$("#batchDel").click(function() {
			var arr=[];
			$(".choose:checked").each(function() {
				var id=$(this).data("id");
				arr.push(id);
			});
			if(arr.length>0){
				$.ajax({
					url:"<%=path%>/manage/OfficialNewsServlet?action=batchDelete",
					data:{ids:arr.toString()},
					success:function(){
						for(var i=0;i<arr.length;i++){
							$("#tr"+arr[i]).remove();
						}
					}
				})
			}
		});
		
	});
</script>